#ifndef _CKLOGFILE_H_
#define _CKLOGFILE_H_



#include <mutex>
#include <fstream>

namespace K_Engine
{	
	enum LOG_TYPE
	{
		UNKNOW = 0,
		NORMAL = 1,
		WARNING = 2,
		ERROR = 3
	};
		
	class CKLogFile
	{
	protected:
		std::ofstream m_filefd;
		std::mutex m_mutex;
		std::string m_strFileName;
		
	protected:
		void Write(const std::string strText);
		void WriteLog(const std::string strText, LOG_TYPE level);
		bool bOpenFile();
		void Lock();
		void UnLock();
		
	public:
		CKLogFile(const std::string strFileName = "Log.log");
		virtual ~CKLogFile();
		virtual void Log(const std::string& strText, LOG_TYPE level = NORMAL);
		void SetFileName(const std::string& strFileName);
		const std::string& GetFileName();
		bool IsOpen();
		void Close();
	
	private:
		/**
		 * 屏蔽函数
		 */
		CKLogFile(const CKLogFile&);
		CKLogFile& operator = (const CKLogFile&);
	};
}

#endif // ! _CKLOGFILE_H_
